package com.linksfield.topup.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置类
 *
 * @author: lm
 * @date: 2019-11-22
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * 读取application.yml配置文件中对swagger的配置
     */
    @Value("${swagger2.host}")
    private String host;

    //http://localhost:8092/topup/swagger-ui.html#/
    //http://localhost:8093/topup_test/swagger-ui.html#/

    @Bean
    public Docket createLogin() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("3.0充值管理系统：登录")
                .host(host)
                //.host("wx.linksfield.net")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.linksfield.topup.controller.login"))
                .build();
    }

    @Bean
    public Docket createLogin1() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("3.0充值管理系统：套餐管理")
                .host(host)
                //.host("wx.linksfield.net")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.linksfield.topup.controller.planmanage"))
                .build();
    }

    @Bean
    public Docket createLogin2() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("3.0充值管理系统：订单管理")
                .host(host)
                //.host("wx.linksfield.net")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.linksfield.topup.controller.ordermanage"))
                .build();
    }

    @Bean
    public Docket createLogin3() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("3.0充值管理系统：系统用户管理")
                .host(host)
                //.host("wx.linksfield.net")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.linksfield.topup.controller.accountmanage"))
                .build();
    }

    @Bean
    public Docket createLogin4() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("3.0充值管理系统：H5功能管理")
                .host(host)
                //.host("wx.linksfield.net")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.linksfield.topup.controller.comlinkmanage"))
                .build();
    }

    @Bean
    public Docket createLogin5() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("3.0充值管理系统：概览")
                .host(host)
                //.host("wx.linksfield.net")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.linksfield.topup.controller.anoverview"))
                .build();
    }

    @Bean
    public Docket createLogin6() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("3.0充值管理系统：自动订阅管理")
                .host(host)
                //.host("wx.linksfield.net")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.linksfield.topup.controller.autosubmanage"))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("领科top-up管理后台接口")
                .description("")
                .version("3.0")
                .termsOfServiceUrl("https://wx.linksfield.net")
                .contact(new Contact("", "", ""))
                .build();
    }

}
